<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>添加标签</title>
<link rel="stylesheet" type="text/css" href="layui/css/layui.css" media="all">
<script type="text/javascript" src="js/base64/base64.js"></script>
<script type="text/javascript" src="layui/layui.js"></script>
<script src="https://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">

function ajax(msg) {
	var event = document.createEvent('MessageEvent');
	var origin = window.location.protocol + '//' + window.location.host;
	event.initMessageEvent('MessageReceived', true, true, msg, origin, 1234, window, null);
	document.dispatchEvent(event);
}
// 全局接收消息事件
function messageReceived(res) {
	res = Base64.decode(res);
	res = JSON.parse(res);

	//标签搜索
	if (res.type == "Search/Tags") {
		AddTags(res.data);
	}
	else if(res.type == "Tags/Input")
	{

		$("#name").attr("readonly","readonly");
		$("#name").val(res.data["name"]);
		$("#icon").val(res.data["icon"]);
		$("#indexs").val(res.data["indexs"]);
	}
}

</script>
<style type="text/css">
body{ padding: 10px; }
</style>
</head>
<body>

  <div class="layui-form-item">
    <label class="layui-form-label">名称</label>
    <div class="layui-input-block">
      <input type="text" name="name" id="name" placeholder="请输入名称" autocomplete="off" class="layui-input">
    </div>
  </div>
 	<div class="layui-form-item">
    <label class="layui-form-label">图标</label>
    <div class="layui-input-block">
      <input type="text" name="icon" id="icon" placeholder="请输入图标，可留空" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">排序</label>
    <div class="layui-input-block">
      <input type="text" name="indexs" id="indexs" onkeyup="this.value=this.value.replace(/[^0-9.]/g,'')" placeholder="请输入排序" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" id="Btn" >立即提交</button>
    </div>
  </div>
</body>
<script type="text/javascript">
		/*获取选中的id值*/
		$("#Btn").click(function(){
			var name = $("#name").val();
			var icon = $("#icon").val();
			var indexs = $("#indexs").val();
			var data_opt = {
				type: "Tags/Add",
				data: {
					name : name,
					icon : icon,
					indexs : indexs,
				}
			}
			data_opt = JSON.stringify(data_opt);
			ajax(data_opt);
		});
</script>

</html>
